/*******************************************************************************
 *  CheckBoxElement class
 *******************************************************************************

// example options object
var options = {
    id: 'id',
    name: 'name',
    classes: 'classes',
    value: 'value',
    checked: false,
    onclick: function(){},
    rules:{
        // validation rules here
        messages: {
            // validation messages here
        }
    }
}

*/

/**
 *  Represent checkbox model
 */
var CheckBoxElement = function(options) {
    
    options.placeholder = null;
    options.type = 'checkbox';
    options.value = 1;
    
    // this class should extend an Element class
    $.extend(true, this, new InputElement(options));
    this.getElement()[0].wrapper = this;
    // ------------------------------------------------------- settings
    this.defaults = {
        checked: false
    };
    
    var settings = this.prepareSettings(options);
    
    // ------------------------------------------------------- methods
    this.isChecked = function(){
        return this.getElement().is(':checked');
    }
    
    // ------------------------------------------------------- element creation
    if(settings.checked==true || settings.checked==='true') this.addAttribute('checked', true);
    
    if(settings.onclick) {
        var handler = settings.onclick;
        this.getElement()[0].onclick = function(e){
            if(this.wrapper.isDisabled()) return;
            handler(e, this);
        };
    }
    
    console.log('CheckBoxElement was created with id = '+this.getId());
}